﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SQLite;

/// <summary>
///UDCPage Basic Page
/// </summary>
public class CWSPage : System.Web.UI.Page
{
    public int Uid
    {
        get {
            ReLoginIn();
            return Int32.Parse(Session["LoginUser"].ToString());
        }
        set { Session["LoginUser"] = value; }
    }

    public CWSPage() { }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        ReLoginIn();
    }

    protected int GetDid()
    {
        int did = -1;
        string sqlstr = "select did from cw_user_t where uid = :uid";
        SQLiteParameter[] spc = {
                                new SQLiteParameter(":uid", DbType.UInt32)
                                };
        spc[0].Value = Uid;
        Int32.TryParse(SQLiteHelper.ExecuteScalar(sqlstr, spc).ToString(),out did);
        return did;
    }

    public void LoginOut()
    {
        Session["LoginUser"] = null;
    }

    private void ReLoginIn()
    {
        if (Session["LoginUser"] == null)
        {
            Response.Redirect("~");
            Response.End();
        }
    }
}